package com.caiwangdai.app.ui.verify

import android.content.Context
import android.content.Intent
import com.caiwangdai.app.AppData
import com.caiwangdai.app.R
import com.caiwangdai.app.extension.*
import com.caiwangdai.app.origin.BaseActivity
import com.caiwangdai.app.origin.ToolBarManager
import kotlinx.android.synthetic.main.activity_verify_result.*
import kotlinx.android.synthetic.main.content_verify_result_failure.*
import kotlinx.android.synthetic.main.content_verify_result_success.*

class VerifyResultActivity : BaseActivity() {
    var isSuccess: Boolean = false
    var tip: String = ""

    override fun getLayoutResID() = R.layout.activity_verify_result

    companion object {
        var VERIFY_STATUS: String = "verify_status"
        var VERIFY_TIP: String = "verify_tip"


        fun newInstance(context: Context, isSuccess: Boolean, tips: String = ""): Intent {
            val intent = Intent(context, VerifyResultActivity::class.java)
            intent.putExtra(VERIFY_STATUS, isSuccess)
            intent.putExtra(VERIFY_TIP, tips)
            return intent
        }
    }

    override fun initData() {
        isSuccess = intent.getBooleanExtra(VERIFY_STATUS, false)
        tip = intent.getStringExtra(VERIFY_TIP)
    }

    override fun initView() {
        ToolBarManager.with(this, WMContent).setBackgroundColor(R.color.white)
        if (isSuccess) showSuccessSituation() else showFailureSituation()
    }

    fun showSuccessSituation() {
        content_success.visible()
        content_failure.gone()

        if (!tip.isEmpty()) {
            tv_tip_success.text = tip
        }

        tv_btn_ok.setOnClickListenerPro {
            AppData.closeActivityExceptMain()
        }
    }

    fun showFailureSituation() {
        content_success.gone()
        content_failure.visible()


        if (!tip.isEmpty()) {
            tv_tip_failure.text = tip
        }

        tv_btn_back.setOnClickListenerPro {
            finish()
        }

        tv_btn_try.setOnClickListenerPro {
            finish()
        }
    }

    override fun onBackPressed() {}

}
